package com.cyandpos.pad.utils;

import android.util.Log;

import java.security.MessageDigest;

public class MD5Utils {
    public static final String USER_SETTRING = "52c69e3a57331081823331c4e69d3f2e";
    public static final String PASSWORD_SETTRING = "5d328998af7233cd692cdf0ae1d7b1b3";
    public static String md5(String src){
        String session ="";
        try{
            MessageDigest md5= MessageDigest.getInstance("md5");//返回实现指定摘要算法的 MessageDigest 对象。
            md5.update(src.getBytes());//先将字符串转换成byte数组，再用byte 数组更新摘要
            byte[] nStr = md5.digest();//哈希计算，即加密
            session = bytes2Hex(nStr);//加密的结果是byte数组，将byte数组转换成字符串
        }catch(Exception e){
            return "";
        }
        return session;
    }

    public static String bytes2Hex(byte[] bts) {
        String des = "";
        String tmp = null;
        for (int i = 0; i < bts.length; i++) {
            tmp = (Integer.toHexString(bts[i] & 0xFF));
            if (tmp.length() == 1) {
                des += "0";
            }
            des += tmp;
        }
        return des;
    }
}
